package com.lx.ngsl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;

@SpringBootApplication
public class NgslApplication {// extends SpringBootServletInitializer

//	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
//		return builder.sources(NgslApplication.class);
//	}
	public static void main(String[] args) {

		SpringApplication.run(NgslApplication.class, args);
	}
	
	/**
	 * 使用fastJson作为json解析器
	 * @Title：fastJsonMessageConverters 
	 * @return 
	 * @return ：HttpMessageConverters 
	 * @throws
	 */
	@Bean
	public HttpMessageConverters fastJsonMessageConverters() {
		
		FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
		//添加fastJson的配置信息，对json进行格式化
		FastJsonConfig config = new FastJsonConfig();
		config.setSerializerFeatures(SerializerFeature.PrettyFormat);
		
		//处理中文乱码问题
	    List<MediaType> fastMediaTypes = new ArrayList<>();
	    fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
	    fastConverter.setSupportedMediaTypes(fastMediaTypes);
	
		//在converter中添加配置信息
		fastConverter.setFastJsonConfig(config);
		
		HttpMessageConverter<?> converter = fastConverter;
		
		return new HttpMessageConverters(converter);
	}
	

}
